{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2025 Teclib' and contributors.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{% import 'components/form/fields_macros.html.twig' as fields %}

{% set full_width = full_width|default(false) %}
{% if item.isNewItem() %}
    {{ fields.checkboxField('_init_password', 0, __('Send an email to the user to set their own new password.'), {
        full_width: full_width,
    }) }}
{% endif %}
{{ fields.passwordField('password', '', __('Password'), {
    id: 'password',
    clearable: false,
    additional_attributes: {
        autocomplete: 'off',
    },
    full_width: full_width,
}) }}
{{ fields.passwordField('password2', '', __('Confirm password'), {
    clearable: false,
    additional_attributes: {
        autocomplete: 'off',
    },
    full_width: full_width,
}) }}
{% if config('use_password_security') %}
    {{ fields.htmlField('password_checks', include('components/user/password_security_checks.html.twig', {list_view: true}), __('Password security policy'), {
        full_width: full_width,
    }) }}
{% endif %}
<script>
    $('input[name=_init_password]').on('change', function() {
        $('input[name=password]').closest('.form-field')
            .toggleClass('d-none', $(this).is(':checked'))
            .val('');
        $('input[name=password2]').closest('.form-field')
            .toggleClass('d-none', $(this).is(':checked'))
            .val('');
        $('.password-security-checks').closest('.form-field').toggleClass('d-none', $(this).is(':checked'));
    });
    {% if config('use_password_security') %}
        $('input[name=password]').on('input', passwordCheck);
    {% endif %}
</script>
